# _*_ coding:utf-8 _*_
from utils.HTMLTestRunner import HTMLTestRunner
import time
import unittest
import os
import logging

# 设置日志文件及格式
proDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
filePath = proDir + "\\ApiAutoTest\\result\\output.log"
logging.basicConfig(filename=filePath, level=logging.INFO,format='%(asctime)s %(filename)s[line:%(lineno)d] %(message)s', datefmt='%Y-%m-%d')

# 定义测试集合
suite = unittest.TestSuite()
all_case = unittest.defaultTestLoader.discover(r'D:\WorkSpace_Python\ApiAutoTest\testCase','test_*.py')
for case in all_case:
    # 循环添加case到测试集合里面
    suite.addTests(case)
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
filename = proDir + "\\ApiAutoTest\\result\\" + now + "TestResult.html"
print(filename)
fp = open(filename, "wb")
runner = HTMLTestRunner(stream=fp, title=u"BitunAPi自动化测试", description=u"用例执行情况",verbosity=2)
runner.run(suite)
fp.close()